﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace thinger.DelegateApp2
{
    public delegate void ReceiveDelegate(string msg);
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void ReceiveMsg(string msg)
        {
            this.txtReceiveMsg.Text += msg + "\r\n";
        }
        private ReceiveDelegate receiveDelegate = null;
        private void btnCreateChild_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < 4; i++)
            {
                FrmChild child = new FrmChild();
                child.Text += child.Text + " " + i;
                //child.ChildDelegate += ReceiveMsg;
                child.Show();
                receiveDelegate += child.ReceiveMsg;
            }
        }

        private void btnBroadcastMsg_Click(object sender, EventArgs e)
        {
            this.receiveDelegate.Invoke(this.txtBroadMsg.Text);
        }
    }
}
